package com.pactera.madp.cp.controller.oms.remind;

import com.pactera.madp.common.core.util.R;
import com.pactera.madp.common.security.annotation.Inner;
import com.pactera.madp.cp.api.dto.clientLossManagement.RemindTaskDTO;
import com.pactera.madp.cp.api.entity.CorpEntity;
import com.pactera.madp.cp.service.IContactService;
import com.pactera.madp.cp.service.ICorpService;
import com.pactera.madp.cp.service.RemindTaskRecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author zkd
 * @date 2022/5/13 11:09
 */
@RestController
@AllArgsConstructor
@RequestMapping("/remindtask")
@Api(value = "remindtask", tags = "未交流提醒定时任务记录")
public class RemindTaskRecordsController {

    @Autowired
    private RemindTaskRecordsService remindTaskRecordsService;
    @Autowired
    private IContactService contactService;
    @Autowired
    private ICorpService corpService;

    @PostMapping("/create")
    @Inner
    @ApiOperation(value = "新增成员未交流提醒定时任务")
    public R createTask(@RequestBody RemindTaskDTO dto) {
        return remindTaskRecordsService.createTask(dto);
    }

    @GetMapping("/list-finished-ids")
    @Inner
    @ApiOperation(value = "获取已结束的提醒任务记录id列表")
    public List<Integer> getRecordFinishedIdList() {
        return remindTaskRecordsService.getRecordFinishedIdList();
    }

    @GetMapping("/nocommunication-maplist")
    @Inner
    @ApiOperation(value = "获取未交流成员客户map列表")
    public List<Map<String,String>> getNoCommunicationMapList(@RequestParam(value = "corpId") Integer corpId) {
        return contactService.getNoCommunicationMapList(corpId);
    }

    @PostMapping("/batch-create-task")
    @Inner
    @ApiOperation(value = "远程调用-批量创建成员未交流提醒定时任务")
    public void batchCreateTask() {
        List<CorpEntity> list = corpService.list();
        list.forEach(l -> {
            remindTaskRecordsService.batchCreateTask(l.getCorpId());
        });
    }

}
